/**
 * Created by Administrator on 2018/4/2.
 */
/**
 * Created by Administrator on 2018/3/31.
 */
(function () {
    let $vue = null;
    let constantParams = JSON.parse(IOT.getSessionStore(URI.OPERATE.SINGLELAMP.DETAIL.PAGE));
    let map = null;
    let currentNodes=new Array();
    $vue = new Vue({
        el: '.detail-groups-single-hook',
        data: {
            control_type:[{id: 1, name: '故障A'}, {id: 2, name: '故障B'},{id: 3, name: '故障C'}],
            info:{
                lightName:'灯盏A',
                onenetCode:'123456788',
                conCategory:'1',
                deviceId:'1245676',
                proCode:'333',
                groupCode:'1',
                lampCode:'s222112',
                proName:'aaaa',
                installTime:'2018-03-23',
                imei:"111111111111",
                imsi:"1133311121",
                remark:'检查通过，无故障',
                IMEI:"",
                lng:'112.23',
                lat:'34.12'
            },
            net:{
                endHeartTimes:'2',
                endReplyTimes:'3',
                endResendNum:'2',
                serviceAPN:'234566',
                serviceName:'app',
                servicePassword:'qwe1234',
                serviceAddress:'192.168.20.112',
                serviceTCP:'20',
                proviceId:'11',
                cityId:'23',
                phone:'13567890987'
            },
            itemStateList:[
                {
                    id:'1',eleV:'12',eleA:'23',eleW:'21',eleL:'34'
                },
                {
                    id:'2',eleV:'22',eleA:'21',eleW:'22',eleL:'14'
                }
            ]
        },
        created: function () {

        },
        methods: {
            goBack: function () {
                M.Page.emitPrePage();
            },
        },
        mounted: function () {
            this.$nextTick(() => {

                initMap();
                var mapData =[
                    {lat:26.2,lng:114.45,name:'灯泡A'},
                    {lat:33.2,lng:110.45,name:'灯泡Ad'},
                    {lat:29.1,lng:116.45,name:'灯泡Asb'},
                    {lat:31.2,lng:104.45,name:'灯泡Abc'},
                    {lat:29.2,lng:101.45,name:'灯泡Af'}
                ];
                drawOverlays(mapData);
            });
        }
    });
    //地图初始化
    var initMap = function() {
        map = new BMap.Map("add_single_map", {enableMapClick: false});    // 创建Map实例
        var point = new BMap.Point(103.73, 36.03);  // 创建点坐标
        map.centerAndZoom(point, 5); //初始化地图,设置中心点坐标和地图级别
        map.enableScrollWheelZoom(true);  //开启鼠标滚轮缩放*/
        map.addControl(new BMap.NavigationControl());
        map.addControl(new BMap.ScaleControl());
        map.addControl(new BMap.OverviewMapControl());
    };
    var setCity = function(){
        var cityCenter = function(result){
            var cityName = result.name;
            map.setCenter(cityName);
        };
        var myCity = new BMap.LocalCity();
        myCity.get(cityCenter);
    };
    //地图画标注点方法
    var drawOverlays = function(data) {

        map.clearOverlays();
        var pointArray = new Array();
        $.each(data, function (i, node) {
            var point = new BMap.Point(node.lng, node.lat);
            var fnIcon = new BMap.Icon("img/icon/icon1.png", new BMap.Size(32,51), {
                offset: new BMap.Size(0, 0),
            });
            var marker = new BMap.Marker(point, {icon: fnIcon});        // 创建标注
            map.addOverlay(marker);
            pointArray.push(point);
            /*  marker.addEventListener("click", function (e) {
             });*/
        });
        map.setViewport(pointArray);
    }
})();